﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;

namespace Windy.Transformations.Test
{
    public class TransformationTests
    {
        [Fact()]
        public void ApplyToTest()
        {
            int[] input = new int[] { -1, 0, 1, 2, 3 };
            int[] expected = new int[] { 0, 1, 2, 2, 3, 3, 3 };

            var transformation = new Transformation<int, int, int>
            (
                (i) => i,
                new BlockTransformRule<int>((i) => i < 0),
                new TransferTransformRule<int, int>(0),
                new ExpandTransformRule<int, int, int>((i) => true, TestOutputGenerators.Repeat)
            );

            var output = transformation.ApplyTo(input).ToArray();

            Assert.Equal(expected, output);
        }

        [Fact()]
        public void ApplyToListTest()
        {
            var input = new List<int>(new int[] { -1, 0, 1, 2, 3 });
            var expected = new int[] { 0, 1, 2, 2, 3, 3, 3 };

            var ruleSet = new Transformation<int, int, int>
                        (
                            (i) => i,
                            new BlockTransformRule<int>((i) => i < 0),
                            new TransferTransformRule<int, int>(0),
                            new ExpandTransformRule<int, int, int>((i) => true, TestOutputGenerators.Repeat)
                        );

            ruleSet.ApplyToList(input);

            Assert.Equal(expected, input.ToArray());
        }

        [Fact()]
        public void ApplyToListTest2()
        {
            var input = new List<int>(new int[] { -1, 0, 1, 2, 3 });
            var expected = new int[] { 0, 1, 1, 2, 1, 2, 3 };

            var ruleSet = new Transformation<int, int, int>
                        (
                            (i) => i,
                            new BlockTransformRule<int>((i) => i < 0),
                            new TransferTransformRule<int, int>(0),
                            new ExpandTransformRule<int, int, int>((i) => true, TestOutputGenerators.Index)
                        );

            ruleSet.ApplyToList(input);

            Assert.Equal(expected, input.ToArray());
        }
    }
}
